package com.lj.ucenter.controller;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lj.ucenter.entity.Member;
import com.lj.ucenter.entity.vo.LoginVo;
import com.lj.ucenter.entity.vo.RegisterVo;
import com.lj.ucenter.service.MemberService;
import com.lj.utils.utils.JwtUtils;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2021-06-30
 */
@RestController
@RequestMapping("/ucenter/member")
@CrossOrigin
public class MemberController {

    @Autowired
    private MemberService memberService;

    @ApiOperation("会员登录")
    @PostMapping("/login")
    public String login(@RequestBody LoginVo loginVo){
        return memberService.login(loginVo);
    }

    @ApiOperation("会员注册")
    @PostMapping("/register")
    public Boolean register(@RequestBody @Validated RegisterVo registerVo){
        return memberService.register(registerVo);
    }

    @ApiOperation("token获取用户信息")
    @GetMapping("/userInfo")
    public Member userInfo(HttpServletRequest request){
        String id = JwtUtils.getMemberIdByJwtToken(request);
        return memberService.getById(id);
    }


}

